<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: LanguageCreate.php 361 2010-02-03 08:08:44Z steen.rabol@gmail.com $
 *
 */

Prado::using('Application.Common.Data.PortalLanguageRecord');
Prado::using('Application.Common.Data.PortalLanguageStringRecord');

class LanguageCreate extends PortalAdminPage
{
	public static function ToolMenuName()
	{
		return Prado::localize('Create language');
	}

	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->PageTitle = Prado::localize("Create language");

		if(!$this->IsPostBack)
		{
			$this->dlSourceLanglist->PromptText	= Prado::localize("Select");
			$this->dlSourceLanglist->PromptValue	= 0;
			$this->dlSourceLanglist->DataSource	= $this->DataAccess->createCommand("select culture,name from tbllanguages where active=1")->query();
			$this->dlSourceLanglist->dataBind();

			$this->dlDestLanglist->PromptText	= Prado::localize("Select");
			$this->dlDestLanglist->PromptValue	= 0;
			$this->dlDestLanglist->DataSource	= $this->DataAccess->createCommand("select culture,name from tbllanguages where active=0")->query();
			$this->dlDestLanglist->dataBind();

		}
	}

	public function CreateLanguage()
	{
		if($this->IsValid)
		{
			$source	= $this->dlSourceLanglist->SelectedValue;
			$dest	= $this->dlDestLanglist->SelectedValue;
			$dr		= $this->DataAccess->createCommand("select * from tbllangstrings where culture='$source'")->query();

			if($dr)
			{
				foreach($dr as $r)
				{
					$lrec	= new PortalLanguageStringRecord();
					$lrec->culture		= $dest;
					$lrec->lkey			= $r['lkey'];
					$lrec->fromvalue	= $r['fromvalue'];
					$lrec->tovalue		= $r['tovalue'];
					$lrec->save();
				}

				$langRec	= PortalLanguageRecord::finder()->findByculture($dest);
				if($langRec)
				{
					$langRec->active	= 1;
					$langRec->save();
				}
			}
		}
		$this->gotoPage('Admin.LanguageMan');
	}
}

?>